using System;
using Common.Enumerations;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.Dto.Enumerations;
using WebApp.ModelService;

namespace IntegrationTests.ModelServices
{
    public class MemberModelServiceTester : IntegrationTestBase
    {
        [Test]
        public void ShouldGetById()
        {
            var member = new Member
            {
                Id = GuidComb.New(),
                Code = "Admin",
                Name = "Admin",
                DateOfBirth = DateTime.Now.AddYears(-20),
                Address = "adminAddress",
                Email = "sunny@sanelib.com",
                Mobile = "9099791517",
                ScreenMessage = "Hi, Admin",
                ValidFrom = DateTime.Now.AddMonths(-1),
                ValidTo = DateTime.Now.AddMonths(2),
                SendSms = true,
                SendEmail = true,
                UsePrint = true,
                Block = false,
                Role = Role.ApplicationOwner,
                UserStatus = UserStatus.Active,
                ImageData = ImageUtility.NoImageData
            };

            Persist(member);

            var memberModelService = GetInstance<IMemberModelService>();
            var response = memberModelService.GetMemberDetailById(member.Id);

            Assert.AreEqual(response.Detail.Id, member.Id);
        }

        [Test]
        public void ShouldTestGetDetailById()
        {
            var member = new Member
            {
                Id = GuidComb.New(),
                Code = "Admin",
                Name = "Admin",
                DateOfBirth = DateTime.Now.AddYears(-20),
                Address = "adminAddress",
                Email = "sunny@sanelib.com",
                Mobile = "9099791517",
                ScreenMessage = "Hi, Admin",
                ValidFrom = DateTime.Now.AddMonths(-1),
                ValidTo = DateTime.Now.AddMonths(2),
                SendSms = true,
                SendEmail = true,
                UsePrint = true,
                Block = false,
                Role = Role.ApplicationOwner,
                UserStatus = UserStatus.Active,
                ImageData = ImageUtility.NoImageData
            };

            var note = new Note
            {
                Id = GuidComb.New(),
                Name = "Details",
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Member,
                ReferenceId = member.Id,
                ReferenceName = member.Name,
                Description = "Finance Account"
            };

            var attachment = new Attachment
            {
                Id = GuidComb.New(),
                Name = "SanelibAccounts",
                FileType = "image/png",
                FileSize = 10,
                FileHashCode = "gsdhf35989fsnl1324ywefnj",
                ImageData = ImageUtility.NoImageData,
                EntityType = EntityType.Account,
                ReferenceId = member.Id,
                ReferenceName = member.Name,
                Description = "This file for Account of sanelib"
            };

            Persist(member, note, attachment);

            var memberModelService = GetInstance<IMemberModelService>();

            var response = memberModelService.GetMemberDetailById(member.Id);

            Assert.AreEqual(response.Detail.Id, member.Id);
            Assert.AreEqual(response.Notes[0].Id, note.Id);
            Assert.AreEqual(response.Attachments[0].Id, attachment.Id);
        }
    }
}